package heima3_2.cn.osc.hold;


import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import net.oschina.app.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import heima3_2.cn.osc.base.BaseHolder;
import heima3_2.cn.osc.base.MyBaseAdapter;
import heima3_2.cn.osc.model.bean.DynamicFragmentBean.Tweet;
import heima3_2.cn.osc.ui.activity.DynamicDetailActivity;

/**
 * Created by 超能浣熊 on 2017/1/15.
 */

public class DynamicHold extends BaseHolder<Tweet> {
    @Bind(R.id.item_headImage)
    CircleImageView itemHeadImage;
    @Bind(R.id.item_name)
    TextView itemName;
    @Bind(R.id.item_comment)
    TextView itemComment;
    @Bind(R.id.item_time)
    TextView itemTime;
    @Bind(R.id.item_image_ilike)
    ImageView itemImageIlike;
    @Bind(R.id.item_image_comment)
    ImageView itemImageComment;
    @Bind(R.id.item_likepeople)
    TextView itemLikepeople;

    public int userID=0;


    public DynamicHold(Context context, ViewGroup parent, MyBaseAdapter<Tweet> adapter, int position, Tweet bean) {
        super(context, parent, adapter, position, bean);
    }

    @Override
    public View onCreateView(final Context context, ViewGroup parent, int position, Tweet bean) {
        View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_item, parent, false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(context, DynamicDetailActivity.class);
                i.putExtra("userID",userID);
                context.startActivity(i);
            }
        });
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void onRefreshView(Tweet bean, int position) {
        userID=bean.getId();
        itemName.setText(bean.getAuthor());
        itemComment.setText(bean.getBody());
        itemTime.setText(bean.getPubDate());
        Picasso.with(context).load(bean.getPortrait()).resize(50,50).centerCrop().into(itemHeadImage);
    }
}
